Welcome![Sign In][Sign Up]
Location:
Search - 3D C

Search list

[Other用c编写的N*N的螺旋矩阵源代码

Description:

/*
实现效果:
1 2 6 7 15
3 5 8 14 16
4 9 13 17 22
10 12 18 21 23
11 19 20 24 25
*/
#include <stdio.h>
#define N 5 //阶数,即N*N的螺旋矩阵

void main()
{
    int i, j, num=1, a[N][N];
    for(i=0; i<=N/2; i++)
    {
        for(j=i; j<N-i; j++) a[i][j]=n++;
        for(j=i+1; j<N-i; j++) a[j][N-i-1]=n++;
        for(j=N-i-2; j>i; j--) a[N-i-1][j]=n++;
        for(j=N-i-1; j>i; j--) a[j][i]=n++;
    }
    for(i=0; i<N; i++)
    {
        for(j=0; j<N; j++)
            printf("%2d ",a[i][j]);
        printf("\n");
    }
}
    

 

不知道叫什么,先叫它“回宫图”吧
年初的时候在贴吧瞎逛,看到了一个程序挺有意思,会输出如下的形状:
01 24 23 22 21 20 19
02 25 40 39 38 37 18
03 26 41 48 47 36 17
04 27 42 49 46 35 16
05 28 43 44 45 34 15
06 29 30 31 32 33 14
07 08 09 10 11 12 13
仔细看这个形状,数字是按顺序往里回旋的,觉得很有创意,可是一看源代码头就大了,
每个编程人都知道看别人的代码是很困难的,尤其像这种不知道思路的,所以也就放下
没管了。
昨天上物理课实在是没心思听,就想起这个程序,想了一节课,果然不负有心人,给弄出来了,这个是增强版的,可以输入1-10中的任意个数,然后生成图形。
先看代码,没有注释,所以不好看的懂。
#include<stdio.h>
main()
{
       int n,m,i,j,t,k=1;
       int a[11][11];
       clrscr();
       do{
       printf("please input a number(1-10):");
       scanf("%d",&n);
       }while(n<1||n>10);
       t=n+1;
       for(m=1;m<=t/2;m++)
         {
           for(i=m;i<=t-m;i++)
             {a[i][m]=k;k++;}
           for(j=m+1;j<=t-m;j++)
             {a[i-1][j]=k;k++;}
           for(i=n-m;i>=m;i--)
             {a[i][j-1]=k;k++;}
           for(j=n-m;j>=m+1;j--)
             {a[i+1][j]=k;k++;}
         }
       for(i=1;i<=n;i++)
         {
           for(j=1;j<=n;j++)
             {
               if(a[i][j]<=9) printf("0%d ",a[i][j]);
               else printf("%d ",a[i][j]);       }
           printf("\n");
         }
       getch();
}
就是这样的。


可以更简洁些:

#include<stdio.h>
main()
{
       int n,m,i,j,t,k=1;
       int a[11][11];
       clrscr();
       do{
       printf("please input a number(1-10):");
       scanf("%d",&n);
       }while(n<1||n>10);
       t=n+1;
       for(m=1;m<=t/2;m++)
         {
           for(i=m;i<=t-m;i++)
             a[i][m]=k++;
           for(j=m+1;j<=t-m;j++)
             a[i-1][j]=k++;
           for(i=n-m;i>=m;i--)
             a[i][j-1]=k++;
           for(j=n-m;j>=m+1;j--)
             a[i+1][j]=k++;
         }
       for(i=1;i<=n;i++)
         {
           for(j=1;j<=n;j++)
             {
               if(a[i][j]<=9) printf("0%d ",a[i][j]);
               else printf("%d ",a[i][j]);       }
           printf("\n");
         }
       getch();
}

 


 #include <stdio.h>
#define N 8
main(){
 int i,j,n=1,a[N][N];
 for(i=0;i<=N/2;i++){
  for(j=i;j<N-i;j++)
   a[i][j]=n++;
  for(j=i+1;j<N-i;j++)
   a[j][N-i-1]=n++;
  for(j=N-i-2;j>i;j--)
   a[N-i-1][j]=n++;
  for(j=N-i-1;j>i;j--)
   a[j][i]=n++;
 }
 for(i=0;i<N;i++){
  printf("\n\n");
  for(j=0;j<N;j++)
   printf("%5d",a[i][j]);
 }
}
 

 


                                马踏棋盘问题


#include <stdio.h>
#define N 5
void main(){
 int x,y;
 void horse(int i,int j);
 printf("Please input start position:");
 scanf("%d%d",&x,&y);
 horse(x-1,y-1);
}
void horse(int i,int j){
 int a[N][N]={0},start=0,
  h[]={1,2,2,1,-1,-2,-2,-1},
  v[]={2,1,-1,-2,2,1,-1,-2},
  save[N*N]={0},posnum=0,ti,tj,count=0;
 int jump(int i,int j,int a[N][N]);
 void outplan(int a[N][N]);
 a[i][j]=posnum+1;
 while(posnum>=0){
  ti=i;tj=j;
  for(start=save[posnum];start<8;++start){
   ti+=h[start];tj+=v[start];
   if(jump(ti,tj,a))
    break;
   ti-=h[start];tj-=v[start];
  }
  if(start<8){
   save[posnum]=start;
   a[ti][tj]=++posnum+1;
   i=ti;j=tj;save[posnum]=0;
   if(posnum==N*N-1){
    //outplan(a);
    count++;
   }
  }
  else{
   a[i][j]=0;
   posnum--;
   i-=h[save[posnum>;j-=v[save[posnum>;
   save[posnum]++;
  }
 }
 printf("%5d",count);
}
int jump(int i,int j,int a[N][N]){
 if(i<N&&i>=0&&j<N&&j>=0&&a[i][j]==0)
  return 1;
 return 0;
}
void outplan(int a[N][N]){
 int i,j;
 for(i=0;i<N;i++){
  for(j=0;j<N;j++)
   printf("%3d",a[i][j]);
  printf("\n");
 }
 printf("\n");
 //getchar();
}
用回溯法得到所有的解,但效率较低,只能算出5行5列的

 


Platform: | Size: 4395 | Author: good@588 | Hits:

[GDI-BitmapVC-3D

Description: VC例程:提供有关用VC三维字体编程方法等内容。-Visual C++ Programme: It contains the method of making 3D font.
Platform: | Size: 3658 | Author: 温海燕 | Hits:

[OpenGL program运用Opengl和C实现一个人体面部的三维显示

Description: 通过VC++和OPenGL实现人脸的三维显示,在 vc++6.0下编译通过 -through VC and achieve OpenGL 3D Face, in vc 6.0 compile
Platform: | Size: 385461 | Author: | Hits:

[Special Effectsc实现图像处理常用算法集

Description: 本人收集的关于c实现图像处理常用算法,包括Hough变换,雕刻技术,灰度均衡,图像的3D灰度显示,拉普拉斯高斯边缘检测等等,-I collected on c achieve common image processing algorithms, including the Hough transform, carving, gray balance, 3D gray-scale images, Laplace Gaussian edge detection and so on.
Platform: | Size: 21855 | Author: 陈曙 | Hits:

[CSharp3ìDò

Description: 运动会分数统计源代码程序是用C++编写的
Platform: | Size: 1936 | Author: 于洲 | Hits:

[OpenGL programIntra3D-Software

Description: 基于OpenGL与Windows的交互式三维图形技术以及程序设计。结合配套软件─—交互式三维图形软件开发工具Intra3D 2.0: (1)3D C++ 类库与COM对象库系统设计; (2)3D 交互算法与数据结构设计; (3)3D 图形用户界面设计; (4)使用Visual C++ 和Intra3D 2.0 C++ 类库编写交互式3D 应用程序; (5)使用Visual Basic和Intra3D 2.0 COM类库编写交互式3D 应用程序。 Intra3D 2.0是免费软件,可用于快速开发PC平台的交互式三维图形应用软件,其7万行核心程序全部公开。Intra3D系列版本曾获首届中国大学生电脑大赛软件展示一等奖。 -OpenGL-based and Windows interactive 3D graphics technology, and program design. Combination packages --interactive 3D graphics software development tools intra3D 2.0 : (1) 3D C class library and COM library system design; (2) 3D interactive algorithm and data structure design; (3) 3D graphical user interface design; (4 ) use Visual C and 2.0 C Class intra3D prepared interactive 3D applications; (5) The use of Visual Basic 2.0 and COM library intra3D prepared interactive 3D applications. Intra3D 2.0 is free software that can be used to quickly develop PC platform interactive 3D graphics software application, its 70,000's core public all procedures. Intra3D series won the first version of the Chinese University Computer software display contest won.
Platform: | Size: 5507076 | Author: 胡锦涛 | Hits:

[Other resourceC++3D

Description: 一套C++3D程序设计的示例,绝对真实的源码。-a 3D program design examples, absolutely true source.
Platform: | Size: 966315 | Author: 翟也 | Hits:

[ELanguage4th-3.3d-for-unix

Description: 4tH compiler是一个稍有不同的Forth 编译器,不像标准Forth 引擎所提供的常规编译器。4tH 是一个非常小的编译器,它可以生成字节码,嵌入式C字节码,单独的可执行文件,但是它也可以作为一个脚本语言-4tH compiler is a slightly different Fortran compiler, Unlike standard Forth engine provided by conventional compilers. 4tH is a very small compiler, which can generate byte code, embedded C byte code, a separate executable files, But it also can be used as a scripting language
Platform: | Size: 292336 | Author: zhouwei | Hits:

[OpenGL programbrian

Description: 3D OPENGL CAR C++编程。小车。按一定的轨道运行。-CAR OpenGL 3D C programming. Trolley. A certain path.
Platform: | Size: 868248 | Author: gexingyue | Hits:

[OpenGL program3D

Description: c++ 结合opengl开发的简单3D绘图
Platform: | Size: 3030850 | Author: 上官武 | Hits:

[Other resourceC++for3DGame

Description: 一本关于3D游戏从头编程的书,需要的话欢迎下载
Platform: | Size: 4759836 | Author: myname | Hits:

[Other resourceAlphaTriangles.c

Description: 主要是查看三角的颜色是否匹配,用的是ARGB,采用的是3D公式,但本程序却不能采用2D公式
Platform: | Size: 9148 | Author: 于芳 | Hits:

[Other resource3D.x

Description: Mesh网络开发语言C++,Direct3D
Platform: | Size: 143570 | Author: 郑康臣 | Hits:

[Develop ToolsExample source codes in C++ using 3d studio max mo

Description: Example source codes in C++ using 3d studio max models
Platform: | Size: 960390 | Author: mskia | Hits:

[Multimedia program3D-动态飞行

Description: C++Builder 3D编程-C Builder 3D Programming
Platform: | Size: 826361 | Author: 徐进 | Hits:

[Windows Develop3D Process[20040824]

Description: C++语言开发的处理ply三维模型文件的程序-C + + language processing ply 3D model documentation procedures
Platform: | Size: 68192 | Author: ray | Hits:

[Other resource3D

Description: 实现了3D正方体的旋转. 本程序可用鼠标及键盘控制,鼠标左键即一个虚拟跟踪球,右键可以调用菜单。 键盘控制键分别为:0-7数字键,b,c,i,m,p,r,w
Platform: | Size: 74233 | Author: knight | Hits:

[Graph programc++image

Description: 图像的3D灰度显示、拉普拉斯高斯边缘检测、灰度拉伸、图像缩放等19种处理
Platform: | Size: 21670 | Author: chen | Hits:

[OtherSolidWorks二次开发实例精解(冲模标准件3D图库)

Description: 基于C#的SolidWorks二次开发,实现计划。。。。。。(Two development of SolidWorks based on C#)
Platform: | Size: 15546368 | Author: ronny_lin | Hits:

[CSharp3D STEP Library

Description: 对三维文件.step结构进行解析,以便于C#导入.step进行图像处理。(Analysis of three dimensional file.Step structure)
Platform: | Size: 3781632 | Author: 周生C# | Hits:
« 1 2 3 4 56 7 8 9 10 ... 50 »

CodeBus www.codebus.net